import logging

from pylons import request, response, session, tmpl_context as c, url
from pylons.controllers.util import abort, redirect

from pedetra.lib.base import BaseController, render
from pedetra.lib.auth import UserAuth

log = logging.getLogger(__name__)

class MainController(BaseController):

    def index(self):
        if 'userid' in session:
            return render('/main.mako')
        return render('/login.mako')
    
    def login(self):
        '''/main/login
        
        A POST request with login information'''
        user = UserAuth(request.POST['username'])
        user.login(request.POST['password'])
        return('')
    
    def logout(self):
        '''/main/logout
        
        Clears login information'''
        
        session['userid'] = None
        session.save()
        return('')
